V4#18
Open
gunesahmet wants to merge 6 commits into
Open
Conversation
Updated version number from 5.0 to 4.0 and modified change notes.
Contributor
|
LGTM |
Owner
|
Hi i'll do a proper review soon |
Author
|
Sent new code that automatically corrects the subsequent order due to new fields inserted or fields removed. |
gunesahmet
commented
May 16, 2026
Author
gunesahmet
left a comment
There was a problem hiding this comment.
Added new features and fix version
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
feat: code completion, go-to-definition, ordinal auto-increment (v3.0 → v4.0)
Add three major features to the Cap'n Proto IntelliJ plugin: context-aware code completion, cross-file Ctrl+Click navigation, and automatic ordinal numbering. Four new files (1302 LOC total), one modified file (plugin.xml).
New Files
CapnpSchemaScanner.java
Regex-based scanner that extracts type definitions, constants, annotations, imports, and using-aliases from .capnp file text. Operates without a PSI tree — works directly on raw file text with comment stripping to avoid false matches.
Scanning capabilities:
struct Foo,enum Bar,interface Baz(pattern anchored to 0-4 spaces indent to distinguish from nested)const name :Type = value;annotation name (...) :Type;import "path.capnp"using Alias = import "path.capnp".Typeusing import "path.capnp".Typeusing Alias = Scope.TypeImport resolution — 4-strategy cascade:
Handles absolute paths (leading
/stripped), normalizes for all strategies. Falls back to project-wide type collection when no imports resolve at all.Additional robustness:
stripComments()removes#line comments before regex matching to prevent false positives inside commented-out codegetVirtualFile()null guard: falls back togetOriginalFile().getVirtualFile()for IntelliJ's in-memory completion copies where the direct virtual file reference is nullallScope(project)instead ofprojectScope(project)so that .capnp files from libraries/dependencies are also discoverableData classes: ScanResult, TypeInfo (kind/name/nested), ImportInfo (path/alias/specificType), AliasInfo (alias/target).
Utility methods:
collectVisibleTypes(),collectProjectTypes(),collectVisibleAnnotations(),getEnumValues(),getStructFields().CapnpCompletionContributor.java
Context-aware auto-completion registered via
completion.contributorextension point. Analyzes caret position by scanning backwards through the file text to determine what kind of completion to offer.Context detection (analyzeContext method): Scans backwards from the caret, first skipping any partial identifier the user is currently typing, then skipping whitespace, to find the preceding token:
Completion items with insert handlers:
List→ inserts()and positions caret between parenthesesimport→ inserts"";and positions caret between quotesstruct,enum,interface,const→ appends trailing spacePriority ordering:
Built-in type names are deduplicated against user-defined types to avoid showing
Texttwice when a project also defines a type namedText.CapnpGotoDeclarationHandler.java
Implements
GotoDeclarationHandlerto enable Ctrl+Click (and Ctrl+B) navigation from type references to their definitions.Resolution order:
getIdentifierAt()which walks forward and backward from the offset to find word boundariesusing Foo = import "bar.capnp".Baz, clicking onFooresolves to theBazdefinition in bar.capnpDefinition matching: Uses parameterized regex patterns (TYPE_DEF_LINE, CONST_DEF_LINE, ANNOTATION_DEF_LINE, ENUMERANT_LINE) where the target name is injected via
Pattern.quote(). After finding a regex match, locates the exact character offset of the name within the match and returnsfile.findElementAt(offset). IntelliJ then opens that file and positions the cursor at the definition.CapnpOrdinalTypedHandler.java
Implements
TypedHandlerDelegateto auto-insert the next ordinal number when the user types@after a field or enumerant name.Trigger conditions (shouldAutoInsert):
@(after skipping whitespace) must be the end of an identifier (field name / enumerant name / method name){, or;(indicating a declaration position, not a type or value context)@0xABCD), after:or=, or inside strings/commentsScope-aware ordinal search (findMaxOrdinal):
{viafindBlockStart()(walks backwards counting brace depth, skipping strings and comments)}viafindBlockEnd()(walks forward)@Npatterns at depth 0 and depth 1@3inside a union within a struct must be counted when determining the next ordinal for a field in the same struct@0x...hex patterns (type IDs, not ordinals)Insert behavior:
(max + 1)as a string immediately after the@character0(first field)Result.STOPto prevent further handler processingExample flow:
Nested union example: